package com.ruoyi.system.api.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteDynamicSqlService;
import com.ruoyi.system.api.domain.DynamicSql;

/**
 * 动态SQL服务降级处理
 */
@Component
public class RemoteDynamicSqlFallbackFactory implements FallbackFactory<RemoteDynamicSqlService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteDynamicSqlFallbackFactory.class);

    @Override
    public RemoteDynamicSqlService create(Throwable throwable)
    {
        log.error("动态SQL服务调用失败:{}", throwable.getMessage());
        return new RemoteDynamicSqlService()
        {
            @Override
            public R<Integer> doUpdate(DynamicSql dynamicSql)
            {
                log.error("执行动态SQL更新失败: {}", throwable.getMessage(), throwable);
                return R.fail("执行SQL失败:" + throwable.getMessage());
            }
        };
    }
}
